package jxtend.processor.eclipse.visitor.handler.impl;

import jxtend.processor.eclipse.utils.EclipseProcessorUtils;
import jxtend.processor.eclipse.visitor.handler.ASTNodeHandlerVisitorContext;

import org.eclipse.jdt.internal.compiler.ast.MarkerAnnotation;
import org.eclipse.jdt.internal.compiler.ast.SingleTypeReference;
import org.eclipse.jdt.internal.compiler.lookup.BlockScope;
import org.eclipse.jdt.internal.compiler.lookup.ClassScope;
import org.eclipse.jdt.internal.compiler.lookup.Scope;

@SuppressWarnings("restriction")
/* default */ final class OverrideAnnotationUtils {
	public static MarkerAnnotation createJavaLangOverrideAnnotation(
			ASTNodeHandlerVisitorContext context, int sourceStart, int sourceEnd, Scope scope) {
		SingleTypeReference overrideAnnotationTypeReference = new SingleTypeReference("Override".toCharArray(),
				EclipseProcessorUtils.encodePos(sourceStart, sourceEnd));

		MarkerAnnotation result = new MarkerAnnotation(overrideAnnotationTypeReference, sourceStart);

		if (scope instanceof BlockScope) {
			context.resolveExpression(result, (BlockScope) scope);
		} else {
			assert scope instanceof ClassScope;

			context.resolveExpression(result, (ClassScope) scope);
		}

		return result;
	}

	private OverrideAnnotationUtils() {
		// Utility class
	}
}
